<?php


namespace app\api\controller\v33;


use app\aliyun\controller\AliyunFilterWord;
use app\api\controller\v2\Auth;
use app\common\cachemodel\AppConfig;
use app\common\cachemodel\ArticleComment;
use app\common\cachemodel\ArticleCommentReply;
use app\common\cachemodel\Goods;
use app\common\cachemodel\ZhunleActivity;
use app\common\cachemodel\zlcr2\Zlcr2QuestionUserView;
use app\common\cachemodel\zlcr2\Zlcr2UserAddQuestion;
use app\common\cachemodel\zlcr2\Zlcr2UserQuestion;
use app\common\cachemodel\zlcr2\Zlcr2UserQuestionComment;
use app\common\cachemodel\zlcr2\Zlcr2UserSameQuestion;
use app\common\cachemodel\ZlcrAppeal;
use app\common\cachemodel\ZlcrAstr;
use app\common\cachemodel\ZlcrAstrMessage;
use app\common\cachemodel\ZlcrTag;
use app\common\cachemodel\ZlUserVip;
use app\common\lib\SensorsData;
use app\common\lib\tarot\Tarot;
use app\common\lib\Util;
use app\common\model\Recode;
use app\common\model\User;
use app\common\model\UserPush;
use think\Cache;
use think\Env;
use think\Log;
use think\response\Json;
use XznsTools\cache\CacheManage;

class UserQuestionAnswer extends Auth
{
    /**
     * 获取提问信息 提问介绍信息
     */
    public function getAskQuestionIntro()
    {
        $qid = input('qid/s', '');
        $qtype = input('qtype/d', 0);
        $is_huawei = 0;
        if (Util::IsHuaweiAndOppo() && !Util::huaweiIsShowAll())
        {
            $is_huawei = 1;
        }

        $question = '';
        $questionType = 0;
        if ($qid)
        {
            if ($qtype === 1)
            {
                $questionInfo = (new Zlcr2UserQuestion())->getInfoById($qid, ['question']);
            } else
            {
                $questionInfo = (new \app\common\cachemodel\zlcr2\GuessQuestion())->getInfoById($qid, ['question', 'question_type']);

                $questionType = (int)($questionInfo['question_type'] ?? 0);

                // ios 2.9.0版本  获取提问信息接口，将骰子和塔罗类型对调 2=>3  3=>2
                if ($this->request->header('app-type') === 'ios' && Util::CheckAppVersion('2.9.0') === '同')
                {
                    if ($questionType === 2)
                    {
                        $questionType = 3;
                    } elseif ($questionType === 3)
                    {
                        $questionType = 2;
                    }
                }
            }

            $question = $questionInfo['question'] ?? '';
        }

        $goodInfo = (new Goods())->GoodsTypeInfo(22);
        (new ZhunleActivity())->goodsActiveInfo(22, $goodInfo);

        $goodList = [];
        $goodTypeConfig = [
            1 => 'astro',
            2 => 'dice',
            3 => 'tarot',
        ];
        foreach ($goodInfo as $goodItem)
        {
            if (($goodItem['is_add'] === 0) && isset($goodTypeConfig[$goodItem['type']]))
            {
                $activePrice = isset($goodItem['active']) ? $goodItem['active']['price'] : 0;
                $goodList[$goodTypeConfig[$goodItem['type']] . '_price'][] = [
                    'gid' => $goodItem['id'],
                    'type' => 1,
                    'price' => (string)((float)$goodItem['now_prize']),
                    'active_price' => $activePrice,
                    'level_img' => $goodItem['img'],
                    'des' => $goodItem['des'],
                    'selected_des' => $goodItem['select_des'],
                    'img' => '',
                ];
            }
        }
        // 补充一个"暂未开通，敬请等待"的商品
        foreach ($goodList as $key => $item)
        {
            $goodList[$key][] = [
                'gid' => 0,
                'type' => 0,
                'price' => 0,
                'level_img' => '',
                'des' => '',
                'selected_des' => '',
                'img' => '/test/question_answer/good_intro.png',
            ];
        }

        if ($questionType)
        {
            $isLimit = 2;
        } else
        {
            $questionAnswerConfig = (new AppConfig())->configInfo('question_answer');
            $isLimit = (int)($questionAnswerConfig['is_limit'] ?? 0);
        }

        $data = [
            'is_limit' => $isLimit,
            'question_title' => $question,
            'price_list' => $goodList,
            'question_title_tips' => '骰子、' . ($is_huawei ? '卡牌' : '塔罗') . '只能问三个月内的事，一次仅限一个问题', // 例如：我今年适合创业吗？我未来两个月会脱单吗？
            'question_title_tips2' => '例如：双子座是不是都是渣男？', // 例如：双子座是不是都是渣男？大家觉得我和摩羯座合拍吗？
            'tips' => [
                'title' => '免费提问怎么问？',
                'des' => "1.针对星座提问，让更多人讨论、解答\r\n2.把问题描述清楚，便于用户理解\r\n3.避免问大家不能解决的问题，如看盘等"
            ],
            'guide_url' => Env::get('host.domain') . '/web/agreement/guide?is_huawei=' . $is_huawei,  // 引导问题H5页面地址
            // v2.8.3新增弹窗提示信息
            'notice_info' => [
                'astro' => null,
                'dice' => [
                    'title' => '特别提示',
                    'des' => "一次悬赏仅限一个问题\r\n骰子提问只针对于“三个月以内具体的事情”。\r\n例如：这次考试会顺利吗？\r\n这个月我可以还清债务吗？\r\n这周内我会脱单吗？",
                ],
                'tarot' => [
                    'title' => '特别提示',
                    'des' => "一次悬赏仅限一个问题\r\n" . ($is_huawei ? "卡牌" : "塔罗") . "提问只针对于“半年内具体事件的发展情况”。\r\n例如：近三个月内我跟他的关系发展如何？\r\n半年内我们能复合吗？",
                ],
                'publish' => [
                    'title' => '悬赏须知',
                    'des' => "一、一次悬赏仅限一个问题，如包含多个问题，咨询师有权只回答1个问题；平台不予退款。\r\n二、骰子提问只针对于“三个月以内具体的事情”。\r\n三、" . ($is_huawei ? "卡牌" : "塔罗") . "提问只针对于“半年内具体事件的发展情况”。\r\n四、星盘提问针对于“长期运势、人生大事件”。",
                    'attention' => '为了你的问答准确度，请务必阅读以上信息',
                ],
            ],
            'question_type' => $questionType
        ];

        return show(config('code.success'), '请求成功', $data);
    }
}
